package com.ruoyi.project.wechatprogram.comment.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.wechatprogram.ordermaster.domain.WxOrderMaster;
import com.ruoyi.project.wechatprogram.ordermaster.mapper.WxOrderMasterMapper;
import com.ruoyi.project.wechatprogram.ordermaster.service.impl.WxOrderMasterServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.wechatprogram.comment.mapper.WxCommentMapper;
import com.ruoyi.project.wechatprogram.comment.domain.WxComment;
import com.ruoyi.project.wechatprogram.comment.service.IWxCommentService;
import com.ruoyi.common.utils.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单评论信息Service业务层处理
 * 
 * @author sxchen
 * @date 2020-04-21
 */
@Service
public class WxCommentServiceImpl implements IWxCommentService {

    private static final Logger log = LoggerFactory.getLogger(WxCommentServiceImpl.class);


    @Autowired
    private WxCommentMapper wxCommentMapper;

    @Autowired
    private WxOrderMasterMapper wxOrderMasterMapper;

    /**
     * 查询订单评论信息
     * 
     * @param id 订单评论信息ID
     * @return 订单评论信息
     */
    @Override
    public WxComment selectWxCommentById(Integer id)
    {
        return wxCommentMapper.selectWxCommentById(id);
    }

    /**
     * 查询订单评论信息列表
     * 
     * @param wxComment 订单评论信息
     * @return 订单评论信息
     */
    @Override
    public List<WxComment> selectWxCommentList(WxComment wxComment)
    {
        return wxCommentMapper.selectWxCommentList(wxComment);
    }

    /**
     * 新增订单评论信息
     * 
     * @param wxComment 订单评论信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertWxComment(WxComment wxComment)
    {
        int states=0;
        try {
            wxComment.setCreateTime(DateUtils.getNowDate());
            int i = wxCommentMapper.insertWxComment(wxComment);
            if(i>0){
                WxOrderMaster wxOrderMaster = new WxOrderMaster();
                wxOrderMaster.setId(wxComment.getWxOrderId());
                wxOrderMaster.setCommentStatus(1);
                wxOrderMasterMapper.updateWxOrderMaster(wxOrderMaster);
            }
        }catch (Exception e){
            log.error("评价订单异常e=",e);
            return 0;
        }
        return 1;
    }

    /**
     * 修改订单评论信息
     * 
     * @param wxComment 订单评论信息
     * @return 结果
     */
    @Override
    public int updateWxComment(WxComment wxComment)
    {
        wxComment.setUpdateTime(DateUtils.getNowDate());
        return wxCommentMapper.updateWxComment(wxComment);
    }

    /**
     * 删除订单评论信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteWxCommentByIds(String ids)
    {
        return wxCommentMapper.deleteWxCommentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除订单评论信息信息
     * 
     * @param id 订单评论信息ID
     * @return 结果
     */
    @Override
    public int deleteWxCommentById(Integer id)
    {
        return wxCommentMapper.deleteWxCommentById(id);
    }
}
